﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Pages/sales/module.master" %>
<script runat="server">

    protected void Page_Load(object sender, EventArgs e)
    {
        string n = Request.QueryString["h"] ?? "500";
        int h = int.Parse(n) - 100;
        
    }

    protected void page_Init(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Session["InvWhere"] = "1=0";

        }
    }

    

    #region search
    protected void btn_search_Click2(object sender, EventArgs e)
    {
        string where = "";
        if (txt_Sn.Text.Trim() != "")
        {
            where = "JobOrderNo='" + SafeValue.SafeInt(txt_Sn.Text.Trim(), 0) + "'";
        }
        else if(this.ASPxDateEdit2.Value!=null&&this.ASPxDateEdit1.Value!=null)
        {
            string dateFrom = this.ASPxDateEdit1.Date.ToString("yyyy-MM-dd");
            string dateTo = this.ASPxDateEdit2.Date.AddDays(1).ToString("yyyy-MM-dd");
            where = string.Format("JobDate>='{0}' and JobDate<'{1}'",dateFrom,dateTo);
        }

        Session["CfsImp"] = where;
        this.dsJobOrder.FilterExpression = where;
    }
    private string GetWhere(string where, string s)
    {
        if (where.Length > 0)
            where += " and " + s;
        else
            where = s;
        return where;
    }
    #endregion

    protected void grid_Order_CustomUnboundColumnData(object sender, ASPxGridViewColumnDataEventArgs e)
    {
        //if (e.Column.FieldName == "CustName")
        //{
        //    Touchmax.JobOrder jo= (sender as ASPxGridView).GetRow(e.ListSourceRowIndex) as Touchmax.JobOrder;
        //    //string sql = "select acctName from Baccount where BaccountID='" + SafeValue.SafeInt(jo.CustCode, 0) + "'";
        //    string sql = "select Name from xxcustomer where oid='" + SafeValue.SafeInt(jo.CustCode, 0) + "'";
        //    e.Value = SafeValue.SafeString(Touchmax.Manager.ORManager.ExecuteScalar(sql), " ");
        //}
    }
    protected void grid_Order_RowCreated(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewTableRowEventArgs e)
    {
        //    if (e.RowType != DevExpress.Web.ASPxGridView.GridViewRowType.Data) return;
        //    ASPxLabel label = grid_Order.FindRowCellTemplateControl(e.VisibleIndex, null, "lab_InvoiceNo") as ASPxLabel;
        //    if (label == null || label.Text.Length < 3)
        //    {
        //        label.Text = "No Invoice";
        //        if (label != null)
        //        {
        //            label.BackColor = System.Drawing.Color.Green;
        //        }
        //    }
        //    else
        //    {
        //        e.Row.ForeColor = System.Drawing.Color.GreenYellow;
        //    }

    }
    protected void grid_Order_HtmlRowPrepared(object sender, ASPxGridViewTableRowEventArgs e)
    {
        if (e.RowType != DevExpress.Web.ASPxGridView.GridViewRowType.Data) return;
        ASPxLabel label = grid_Order.FindRowCellTemplateControl(e.VisibleIndex, null, "lab_InvoiceNo") as ASPxLabel;
        if (label == null || label.Text.Length < 3)
        {
            //e.Row.ForeColor = System.Drawing.Color.;
            //if (label != null)
            //{
            //    label.Text = "         ";
            //    label.BackColor=System.Drawing.Color.Red;
            //}
        }
        else
        {
            //e.Row.Cells[2].BackColor = System.Drawing.Color.LightGreen;

            e.Row.BackColor = System.Drawing.Color.LightGreen;
        }
    }
    
 
    
</script>

<asp:Content ID="Head1" ContentPlaceHolderID="head" Runat="Server">

<script type="text/javascript" src="/jquery.min.js"></script>
     <script type="text/javascript">
         function ShowOrder(invN) {
             parent.Popup('/Pages/Sales/EditPage/OrderEdit.aspx?no=' + invN, 'Service Order', 1000, 500);
            // popubCtr.SetHeaderText('Service Order');
            // popubCtr.SetContentUrl('EditPage/OrderEdit.aspx?no=' + invN);
            // popubCtr.Show();
         }
         function ShowInvoice(invN) {
             popubCtr.SetHeaderText('Invoice');
             popubCtr.SetContentUrl('EditPage/InvoiceEdit.aspx?InvN=' + invN);
             popubCtr.Show();
         }
         function PrintBill(invN) {
             parent.window.open("/rpt/printview.aspx?doc=50&no=" + invN);
         }
    </script>

</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="content" Runat="Server">


        <table cellspacing=10>
        <tr>
        <td width=160 valign=top>
        
        <table>
        <tr>
        <td colspan=2 align="left">
        Quick Navigation
        <hr />
        </td>
        </tr>
        <tr>
        <td colspan=2 align=left>
        <asp:RadioButton GroupName="time" Checked="true" ID="RadioButton0" runat="server" Text = "This Month" /><br /> 
        <asp:RadioButton GroupName="time" ID="RadioButton1" runat="server" Text = "Last Month" /><br /> 
        <asp:RadioButton GroupName="time" ID="RadioButton3" runat="server" Text = "Year to Date" /> <br />
        <asp:RadioButton GroupName="time" ID="RadioButton2" runat="server" Text = "" />
<asp:DropDownList id="ddl" 
           runat="server">
         <asp:ListItem>2010-01</asp:ListItem>
         <asp:ListItem>2010-02</asp:ListItem>
         <asp:ListItem>2010-03</asp:ListItem>
         <asp:ListItem>2010-04</asp:ListItem>
         <asp:ListItem>2010-05</asp:ListItem>
         <asp:ListItem>2010-06</asp:ListItem>
         <asp:ListItem>2010-07</asp:ListItem>
         <asp:ListItem>2010-08</asp:ListItem>
         <asp:ListItem>2010-09</asp:ListItem>
      </asp:DropDownList>

<br />
        </td>
        </tr>
        <tr>
        <td colspan=2>
        <hr />
        </td>
        </tr>
        <tr>
        <td colspan=2 align=left>
       <asp:RadioButton  GroupName="status" Checked="True" ID="RadioButton6" runat="server" Text = "All" /><br /> 
        <asp:RadioButton GroupName="status" ID="RadioButton4" runat="server" Text = "Open" /><br /> 
        <asp:RadioButton GroupName="status" ID="RadioButton5" runat="server" Text = "Closed" /><br />
        </td>
        </tr>
        <tr>
        <td colspan=2>
        <hr />
        </td>
        </tr>
        <tr>
        <td width=60>
                    Order No
                </td>
                <td>
                    <dxe:ASPxTextBox ID="txt_Sn" Width="70" runat="server" Text="">
                    </dxe:ASPxTextBox>
                </td>
                </tr>
        </table>
        </td>
        <td width=800 valign="top">
        
               <wilson:DataSource ID="dsJobOrder" runat="server" ObjectSpace="Touchmax.Manager.ORManager"
            TypeName="Touchmax.OpOrder" KeyMember="Oid" FilterExpression="1=1" />
        
  
        <table width=800>
           <tr>
                
                <td>
                    Date
                </td>
                <td>
                    <dxe:ASPxDateEdit ID="ASPxDateEdit1" Width="100" runat="server" EditFormat="Custom" EditFormatString="dd/MM/yyyy">
                    </dxe:ASPxDateEdit>
                </td>
                <td>
                    To
                </td>
                <td>
                    <dxe:ASPxDateEdit ID="ASPxDateEdit2" Width="100" runat="server" EditFormat="Custom" EditFormatString="dd/MM/yyyy">
                    </dxe:ASPxDateEdit>
                </td>
                <td>
                    <dxe:ASPxButton ID="ASPxButton1" Width="100" runat="server" Text="Search" OnClick="btn_search_Click2">
                    </dxe:ASPxButton>
                </td>
                <td align=right width="350">
                <dxe:ASPxButton ID="ASPxButton9" Width="100" runat="server" Text="Create New" AutoPostBack="False">
                            <ClientSideEvents Click="function(s, e) {
                    ShowOrder(0);
                        }" />
                        </dxe:ASPxButton>
                </td>
            </tr>
        </table>
        <dxwgv:ASPxGridView ID="grid_Order" ClientInstanceName="grid_Order" runat="server"
            DataSourceID="dsJobOrder" Width="800" KeyFieldName="Oid" AutoGenerateColumns="False"
             oncustomunboundcolumndata="grid_Order_CustomUnboundColumnData"  OnHtmlRowCreated="grid_Order_RowCreated" OnHtmlRowPrepared="grid_Order_HtmlRowPrepared" >
            <SettingsPager Mode="ShowAllRecords">
            </SettingsPager>
            <SettingsEditing Mode="EditForm" />
            <SettingsCustomizationWindow Enabled="True" />
            <Settings ShowGroupPanel="false"/>
            <Settings ShowVerticalScrollBar="True" VerticalScrollBarStyle="Virtual" VerticalScrollableHeight="320" />
            <Columns>
                
                <dxwgv:GridViewDataTextColumn Caption="Order No" FieldName="JobNo" VisibleIndex="1" SortIndex="0" SortOrder="Descending">
                    <DataItemTemplate>
                        <a onclick='ShowOrder("<%# Eval("JobNo") %>");'><%# Eval("JobNo") %></a>
                    </DataItemTemplate>
            
                </dxwgv:GridViewDataTextColumn>
                <dxwgv:GridViewDataTextColumn Caption="Order Status" FieldName="JobStatus" VisibleIndex="2">
                </dxwgv:GridViewDataTextColumn>
                <dxwgv:GridViewDataDateColumn Caption="Service Date" FieldName="JobDate" PropertiesDateEdit-DisplayFormatString="MMM dd, yyyy"   VisibleIndex="3">
             
                </dxwgv:GridViewDataDateColumn>
                <dxwgv:GridViewDataTextColumn Caption="Customer" Width="150" FieldName="CustName" VisibleIndex="3">
                </dxwgv:GridViewDataTextColumn>
                <dxwgv:GridViewDataTextColumn Caption="Job Contact" FieldName="CustContact" VisibleIndex="4">
                </dxwgv:GridViewDataTextColumn>
                <dxwgv:GridViewDataTextColumn Caption="Technician" Width="100" FieldName="Tehnician" VisibleIndex="5">
                </dxwgv:GridViewDataTextColumn>
                <dxwgv:GridViewDataTextColumn Caption="Service Type" FieldName="JobType" VisibleIndex="6">
                </dxwgv:GridViewDataTextColumn>
                <dxwgv:GridViewDataSpinEditColumn  Caption="Total Amount" FieldName="Amount"  PropertiesSpinEdit-DisplayFormatString="{0:#,##0.00}"  VisibleIndex="7">
                </dxwgv:GridViewDataSpinEditColumn>
                
               
            </Columns>
                        <Settings ShowFooter="True" />
                        <TotalSummary>
                            <dxwgv:ASPxSummaryItem FieldName="No" ShowInGroupFooterColumn="Order No" SummaryType="Count" />
                        </TotalSummary>
        </dxwgv:ASPxGridView>

        
        
        </td>
  
        </tr>
        
        
        </table>


    
     
        <dxpc:ASPxPopupControl id="popubCtr" runat="server" CloseAction="CloseButton" Modal="True"
            PopupHorizontalAlign="Center" PopupVerticalAlign="Middle" ClientInstanceName="popubCtr"
            HeaderText="Invoice Edit" AllowDragging="True" EnableAnimation="False" height="450"
            width="930" EnableViewState="False">
<ClientSideEvents PopUp="function(s){s.UpdatePosition()}" />
<ContentCollection>
<dxpc:PopupControlContentControl ID="PopupControlContentControl1" runat="server"></dxpc:PopupControlContentControl>
</ContentCollection>
        </dxpc:ASPxPopupControl>
        
   


</asp:Content>

